package cn.mzy;

import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

/**
 * @Package: cn.mzy
 * @ClassName: OrderApp
 * @Date:2022/11/8 18:55
 * @Description:
 */
@SpringBootApplication
// 表明它是客户端
@EnableEurekaClient
// 开启熔断功能
@EnableCircuitBreaker
public class OrderApp {
    public static void main(String[] args) {
        SpringApplication.run(OrderApp.class, args);
    }

    // 配置一个RestTemplate ，Spring封装的一个机遇Restful风格的http客户端 工具
    @Bean
    // @LoadBalanced :让RestTemplate有负载均衡的功能
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    // 随机算法
    @Bean
    public RandomRule randomRule() {
        return new RandomRule();
    }
}